import { Extension } from '@tiptap/core'
import { Plugin, PluginKey } from 'prosemirror-state'
import { nanoid } from "nanoid";
// 获取基础数据格式和处理富文本格式的工具函数
import {
    getSsmlcontent, estimateAudioDuration, processText,
    getTextWidthUsingCanvas, SensitiveWordsReplace
} from '@/views/shotstack/MuseMixedCut/utools/index.js'
export const handleInput = (getEdit) => Extension.create({
    name: 'handleInput',
    addProseMirrorPlugins() {
        return [
            new Plugin({
                key: new PluginKey('handleInput'),
                props: {
                    handleTextInput(view) {
                        // const editor = getEdit();
                        // const jsonData = editor.getJSON()
                        // // 保存当前光标位置
                        // const { from, to } = editor.state.selection;
                        // const newJsoneData = SensitiveWordsReplace(jsonData)
                        // editor.commands.setContent(newJsoneData)
                        // // 恢复光标位置
                        // editor.commands.setTextSelection({ from, to });

                        // 定义关键字和替换规则
                        // const keywordMap = {
                        //     '关键字1': '<span style="color: pink;">关键字1</span>',
                        //     '关键字2': '<span style="color: red;">关键字2</span>',
                        //     '关键字3': '<span style="color: blue;">关键字3</span>',
                        // };

                        // jsonData.content.forEach(ele => {
                        //     ele.content.forEach(item => {
                        //         if (item.type == 'text' && item.text) {
                        //             let newText = node.text;
                        //             for (const [key, value] of Object.entries(keywordMap)) {
                        //                 const regex = new RegExp(`(${key})`, 'g');
                        //                 newText = newText.replace(regex, value);
                        //             }
                        //         }
                        //     })
                        // })
                        // editor.commands.setContent(jsonData)
                        // const { state } = view;

                        // const { doc } = state;

                        // console.log(doc, '当前的文本123123');
                        // doc.descendants((node, pos) => {
                        //     console.log(node, 'node123123');
                        // })

                        // const { from, to, $from, $to } = selection;
                        // const nodeType = state.doc.type.schema.nodes.speak.name


                    },
                },
            })
        ]
    }
});
